# -*- coding: utf-8 -*-
# filename: handle.py
import socket

import web


def getHtmlPage():
    with open("index.html", "rb") as fs:
        HTML_PAGE = fs.read()
    return HTML_PAGE

def getPng(fn):
    with open(fn, "rb") as fs:
        PNG_DATA = fs.read()
    return PNG_DATA

class Handle(object):
    def GET(self, fn):
        # print '<Handle>get'
        # print fn
        if fn != '':
            # print "no null"
            if "favicon.ico" in fn:
                print "favicon.ico"
            elif "png" in fn:
                return getPng(fn)
            else:
                address = ('127.0.0.1', 8080)
                udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                udps.sendto(fn, address)
                udps.close()
        return getHtmlPage()

    def POST(self, fn):
        # print '<Handle>post'
        # print fn
        # postData = web.input()
        # cmd = postData['cmd']
        # print cmd
        return getHtmlPage()


